// pages/account/organizingdata.js
var app = getApp();
var util = require('../../utils/util.js');
import WxValidate from '../../utils/validate';
Page({

    data: {
        // showtab: , //顶部选项卡索引
        tabnav: {
            tabnum: 5,
            tabitem: []
        },
        productList: [],
    },
    onLoad: function () {
        let that = this
        const eventChannel = this.getOpenerEventChannel()
        eventChannel.emit('acceptDataFromOpenedPage', { data: "id" });
        // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
        eventChannel.on('acceptDataFromOpenerPage', function (data) {
            that.setData({
                pid: data
            })
            that.getList()
        })

    },
    // 分享
    onShareAppMessage: function (res) {
        var that = this;
        return {
            title: '贷投狗小程序',
            path: 'pages/account/organizingdata',
            success: function (res) {
                that.shareClick();
            },
            fail: function (res) {
            }
        }
    },
    setTab: function (e) {
        console.log(e)
        const id = e.currentTarget.dataset.id;
        this.setData({
            showtab: id,
        })
        this.findList(id)
    },
    setting: function (e) {
        console.log(e)
        if (e.currentTarget.dataset.item.displayStatus == true) {
            wx.navigateTo({
                url: '/pages/imge/imge',
                success: function (res) {
                    let data = e.currentTarget.dataset.item
                    data.load = true
                    res.eventChannel.emit('acceptDataFromOpenerPage', data)
                }
            })
        }
        // wx.navigateTo({
        //     url: '/pages/account/setting',
        // })
    },
    getList: function () {
        // 子栏目数据
        let that = this
        let pid = that.data.pid
        console.log(that.data.pid)
        util.https(app.globalData.api + "/applet/column/tree/" + pid, "GET", {},
            function (data) {
                if (data.code == 200) {
                    that.setData({
                        'tabnav.tabitem': data.data,
                        showtab: data.data[0].id
                    })
                    let id = data.data[0].id
                    that.findList(id)
                } else {
                    util.toolTip(that, data.message)
                }
            }
        )
    },
    // 根据子栏目id获取数据
    findList: function (id) {
        console.log(id)
        let that = this
        util.https(app.globalData.api + "/applet/column/content/" + id, "GET", {},
            function (data) {
                if (data.code == 200) {
                    console.log(data)
                    that.setData({
                        contentData: data.data
                    })
                } else {
                    util.toolTip(that, data.message)
                }
            }
        )
    }
})